package example.com.dynamicproxy.AMSHook;

import android.content.ComponentName;
import android.util.Log;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author LiuYi
 *         创建时间： 2017/8/15.
 *         功能描述:PMS动态代理方法调用时关联的InvocationHandler
 */

public class PackageManagerHandler implements InvocationHandler {

    private Object mActivityManagerObject;

    PackageManagerHandler(Object mActivityManagerObject) {
        this.mActivityManagerObject = mActivityManagerObject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Log.v("LiuYi","被替换的PackageManager---->PackageManagerHandler");
        if (method.getName().equals("getActivityInfo")) {
            String sPackageName= "example.com.dynamicproxy";
            String sHostClazzName="example.com.dynamicproxy.MainActivity";
            ComponentName componentName = new ComponentName(sPackageName, sHostClazzName);
            args[0] = componentName;
        }
        return method.invoke(mActivityManagerObject, args);
    }
}
